import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        redirect: '/home/user'
    },
    {
        path: '/home',
        redirect: '/home/user'
    },
    {
        path: '/login',
        component: () => import('../views/AdminLogin.vue'),
    },
    {
        path: '/home',
        component: () => import('../layout/ContainerView.vue'),
        children: [ // 嵌套路由
            {
                path: '/home/info',
                component: () => import('../views/HomView.vue'),
            },
            {
                path: '/home/user',
                component: () => import('../views/UserView.vue')
            },
            {
                path: '/home/role',
                component: () => import('../views/RoleView.vue')
            },
            {
                path: '/home/permission',
                component: () => import('../views/PermissionView.vue')
            },
            {
                path: '/home/addUser',
                component: () => import('../views/AddUser.vue')
            },
            {
                path: '/home/editUser',
                component: () => import('../views/EditUser.vue')
            },
            {
                path: '/home/addRole',
                component: () => import('../views/AddRole.vue')
            },
            {
                path: '/home/editRole',
                component: () => import('../views/EditRole.vue')
            },
            {
                path: '/home/addPermission',
                component: () => import('../views/AddPermission.vue')
            },
            {
                path: '/home/editPermission',
                component: () => import('../views/EditPermission.vue')
            }
        ]
    },

    {
        path: '/404',
        component: () => import('../views/404View.vue')
    },
    {
        path: '/*',
        redirect: '/404'
    }
]

// 防止连续点击多次路由报错
let routerPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
    return routerPush.call(this, location).catch(err => err)
}


const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

export default router